import request from '@/utils/request'
import { GET_ARTICLE_LIST } from '../actionTypes'
export const getArticleList = (params) => {
  return async (dispatch) => {
    const res = await request({
      url: '/mp/articles',
      params
    })
    console.log(res, 456789)
    dispatch({
      type: GET_ARTICLE_LIST,
      payload: res.data
    })
  }
}
export const delArticle = (id) => {
  return async () => {
    await request({
      method: 'delete',
      url: `/mp/articles/${id}`
    })
  }
}
export const saveArticle = (data, draft = false) => {
  return async () => {
    await request({
      url: '/mp/articles?',
      method: 'post',
      data,
      params: { draft }
    })
  }
}
export const getOneArticle = (id) => {
  return async () => {
    const res = await request({
      url: '/mp/articles/' + id,
      method: 'get'
    })
    console.log(res, 'wenzhangxiangqing')
    return res.data
  }
}
// 编辑
export const editArticle = (data, draft = false) => {
  return async () => {
    await request({
      url: '/mp/articles/' + data.id,
      method: 'put',
      data,
      params: { draft }
    })
  }
}
